/*
 * 文件名： MerchantSettledServiceImpl.java
 * 
 * 工程名称: bis-service
 *
 * Gopay
 *
 * 创建日期： 2018年1月3日
 *
 * Copyright(C) 2018, by www.gopay.com.cn Inc.All rights reserved.
 *
 * 原始作者: 宣广海
 *
 */
package com.gopay.bis.service.bank.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import com.gopay.bis.service.bank.BankIntrChannConfService;
import com.gopay.common.Result;
import com.gopay.common.constants.bank.BankConstants;
import com.gopay.common.constants.bank.BisBankBusinessProd;
import com.gopay.common.constants.bank.BisBankInterfaceChannel;
import com.gopay.common.constants.proccode.ProcCodeConstants;
import com.gopay.common.domain.bank.MerchantSettledRequest;
import com.gopay.common.domain.bank.merchant.MerchantSettledOrgReqMsg;
import com.gopay.common.domain.bank.merchant.contract.req.ContractAddReqMsg;
import com.gopay.common.domain.bank.merchant.contract.req.ContractDeleteReqMsg;
import com.gopay.common.domain.bank.merchant.contract.req.ContractEditReqMsg;
import com.gopay.common.domain.bank.merchant.contract.req.ContractPayFeeReqMsg;
import com.gopay.common.domain.bank.merchant.contract.req.ContractRelateReqMsg;
import com.gopay.common.domain.bank.merchant.mer.req.MechantAddReqMsg;
import com.gopay.common.domain.bank.merchant.mer.req.MerchantDeleteReqMsg;
import com.gopay.common.domain.bank.merchant.mer.req.MerchantEditReqMsg;
import com.gopay.common.domain.bank.merchant.shop.req.ShopAddReqMsg;
import com.gopay.common.domain.bank.merchant.shop.req.ShopDeleteReqMsg;
import com.gopay.common.domain.bank.merchant.shop.req.ShopEditReqMsg;
import com.gopay.common.domain.bank.merchant.shop.req.ShopOpenIdReqMsg;
import com.gopay.common.domain.bis.BaseBisBankExtConfig;
import com.gopay.common.domain.proccode.ProcCodeInfo;
import com.gopay.common.exception.GopayException;
import com.gopay.common.proccode.DicProcCodeService;
import com.gopay.common.util.spring.SpringContextUtil;
import com.gopay.remote.bank.foundation.MerchantSettledRemoteService;

/**
 * 商戶入驻业务处理
 *
 * @author 宣广海
 *
 * @version
 *
 * @since 2018年1月3日
 */
@SuppressWarnings("unchecked")
@Service("merchantSettledService")
public class MerchantSettledServiceImpl implements MerchantSettledRemoteService {
	/**
	 * 定义日志对象
	 */
	private static Logger logger = LoggerFactory.getLogger(MerchantSettledServiceImpl.class);

	@Resource(name = "bankIntrChannConfService")
	private BankIntrChannConfService bankIntrChannConfService;
	@Resource(name = "dicProcCodeService")
	private DicProcCodeService dicProcCodeService;
	@Resource(name = "aPayPabConfig")
	private Map<String, String> aPayPabConfig;

	@Override
	public Result merchantAdd(MerchantSettledRequest<MechantAddReqMsg> request) throws GopayException {

		logger.info("------------MerchantSettledServiceImpl merchantAdd start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻添加商户请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.merchantAdd(request);
			logger.error("MerchantSettledServiceImpl商户添加请求返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl merchantAdd GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl merchantAdd error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl merchantAdd end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;	
	}

	@Override
	public Result merchantEdit(MerchantSettledRequest<MerchantEditReqMsg> request) throws GopayException {

		logger.info("------------MerchantSettledServiceImpl merchantEdit start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻编辑商户请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.merchantEdit(request);
			logger.error("MerchantSettledServiceImpl商户编辑请求返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl merchantEdit GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl merchantEdit error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl merchantEdit end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;	
	}

	@Override
	public Result merchantDelete(MerchantSettledRequest<MerchantDeleteReqMsg> request) throws GopayException {

		logger.info("------------MerchantSettledServiceImpl merchantDelete start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻删除商户请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.merchantDelete(request);
			logger.error("MerchantSettledServiceImpl商户删除请求返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl merchantDelete GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl merchantDelete error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl merchantDelete end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;	
	}

	@Override
	public Result merchantMctClass(MerchantSettledRequest request) throws GopayException {
		logger.info("------------MerchantSettledServiceImpl merchantMctClass start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻商户分类请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.merchantMctClass(request);
			logger.error("MerchantSettledServiceImpl商户分类请求返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl merchantMctClass GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl merchantMctClass error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl merchantMctClass end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;		
	}

	@Override
	public Result merchantCitic(MerchantSettledRequest request) throws GopayException {
		logger.info("------------MerchantSettledServiceImpl merchantCitic start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻城市编码请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.merchantCitic(request);
			logger.error("MerchantSettledServiceImpl城市编码请求返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl merchantCitic GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl merchantCitic error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl merchantCitic end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;		
	
	}

	@Override
	public Result shopAdd(MerchantSettledRequest<ShopAddReqMsg> request) throws GopayException {
		logger.info("------------MerchantSettledServiceImpl shopAdd start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻添加门店请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.shopAdd(request);
			logger.error("MerchantSettledServiceImpl添加门店请求返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl shopAdd GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl shopAdd error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl shopAdd end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;	
	
	}

	@Override
	public Result shopEdit(MerchantSettledRequest<ShopEditReqMsg> request) throws GopayException {
		logger.info("------------MerchantSettledServiceImpl shopEdit start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻编辑门店请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.shopEdit(request);
			logger.error("MerchantSettledServiceImpl编辑门店请求返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl shopEdit GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl shopEdit error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl shopEdit end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;	
	
	}

	@Override
	public Result shopDelete(MerchantSettledRequest<ShopDeleteReqMsg> request) throws GopayException {
		logger.info("------------MerchantSettledServiceImpl shopDelete start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻删除门店请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.shopDelete(request);
			logger.error("MerchantSettledServiceImpl删除门店请求返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl shopDelete GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl shopDelete error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl shopDelete end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;	
	
	}

	@Override
	public Result shopOpenId(MerchantSettledRequest<ShopOpenIdReqMsg> request) throws GopayException {
		logger.info("------------MerchantSettledServiceImpl shopOpenId start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻获取门店openId和密钥请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.shopOpenId(request);
			logger.error("MerchantSettledServiceImpl获取门店openId和密钥请求返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl shopOpenId GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl shopOpenId error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl shopOpenId end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;	
	
	}

	@Override
	public Result contractPayList(MerchantSettledRequest request) throws GopayException {
		logger.info("------------MerchantSettledServiceImpl contractPayList start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻获取合同支付方式请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.contractPayList(request);
			logger.error("MerchantSettledServiceImpl获取合同支付方式请求返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl contractPayList GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl contractPayList error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl contractPayList end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;	
	
	}

	@Override
	public Result contractPayFee(MerchantSettledRequest<ContractPayFeeReqMsg> request) throws GopayException {
		logger.info("------------MerchantSettledServiceImpl contractPayFee start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻获取合同支付方式费率请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.contractPayFee(request);
			logger.error("MerchantSettledServiceImpl获取合同支付方式费率请求返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl contractPayFee GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl contractPayFee error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl contractPayFee end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;	
	
	}

	@Override
	public Result contractAdd(MerchantSettledRequest<ContractAddReqMsg> request) throws GopayException {
		logger.info("------------MerchantSettledServiceImpl contractAdd start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻添加合同请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.contractAdd(request);
			logger.error("MerchantSettledServiceImpl添加合同返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl contractAdd GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl contractAdd error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl contractAdd end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;	
	
	}

	@Override
	public Result contractEdit(MerchantSettledRequest<ContractEditReqMsg> request) throws GopayException {
		logger.info("------------MerchantSettledServiceImpl contractEdit start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻编辑合同请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.contractEdit(request);
			logger.error("MerchantSettledServiceImpl编辑合同返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl contractEdit GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl contractEdit error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl contractEdit end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;	
	
	}

	@Override
	public Result contractDelete(MerchantSettledRequest<ContractDeleteReqMsg> request) throws GopayException {
		logger.info("------------MerchantSettledServiceImpl contractDelete start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻删除合同请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.contractDelete(request);
			logger.error("MerchantSettledServiceImpl删除合同返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl contractDelete GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl contractDelete error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl contractDelete end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;		
	}

	@Override
	public Result contractRelateShop(MerchantSettledRequest<ContractRelateReqMsg> request) throws GopayException {
		logger.info("------------MerchantSettledServiceImpl contractRelateShop start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻合同关联门店请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.contractRelateShop(request);
			logger.error("MerchantSettledServiceImpl合同关联门店返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl contractRelateShop GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl contractRelateShop error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl contractRelateShop end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;		
	}

	@Override
	public Result uplodeFile(MerchantSettledRequest<MerchantSettledOrgReqMsg> request) throws GopayException {
		logger.info("------------MerchantSettledServiceImpl uplodeFile start-------------");
		long beginTime = System.currentTimeMillis();
		logger.info("商户入驻文件上传请求参数键：" + ToStringBuilder.reflectionToString(request));

		Result result = new Result();
		String beanName = null;
		try {
			checkRequest(request);
			request = buildParam(request);
			//重写调用文件上传接口地址
			request.setUrl(aPayPabConfig.get("PAB_MERCHANT_SETTLED_UPLODE"));		
			// 根据银行通道判断后续业务处理bean
			beanName=getBeanName(request.getChannelCode());
			MerchantSettledRemoteService merchantService = (MerchantSettledRemoteService) SpringContextUtil
					.getBean(beanName);
			result = merchantService.uplodeFile(request);
			logger.error("MerchantSettledServiceImpl文件上传返回处理对象：" + ToStringBuilder.reflectionToString(result));
		} catch (GopayException e) {
			logger.error("MerchantSettledServiceImpl uplodeFile GopayException", e);
			ProcCodeInfo procCodeInfo = dicProcCodeService.getProcCodeInfo(e.getErrCode());
			result.setSuccess(false);
			result.setResultCode(e.getErrCode());
			result.setErrorMsg(procCodeInfo.getMessage());
		} catch (Exception e) {
			logger.error("MerchantSettledServiceImpl uplodeFile error: ", e);
			result.setSuccess(false);
			result.setResultCode(ProcCodeConstants.PROC_CODE_100F1002);
			result.setErrorMsg(e.getMessage());
		}
		logger.info("------ MerchantSettledServiceImpl uplodeFile end，耗时(ms):" + (System.currentTimeMillis() - beginTime));
		return result;		
	}

	/**
	 * 
	 * 功能描述：构建参数
	 *
	 * @param param
	 * @return
	 * 
	 * @author 宣广海
	 *
	 * @since 2018年1月4日
	 *
	 * @update:[变更日期YYYY-MM-DD][更改人姓名][变更描述]
	 */
	@SuppressWarnings("rawtypes")
	private MerchantSettledRequest buildParam(MerchantSettledRequest param) throws GopayException {
		BaseBisBankExtConfig bankConfig = null;
		bankConfig = bankIntrChannConfService.findBaseBisBankExtConfigByBankChannel(BisBankBusinessProd._16,
				BisBankInterfaceChannel.get(param.getChannelCode()), BankConstants.BANK_LOGO_WECHAT);
		param.setMerId(bankConfig.getIntrMernum1());
		param.setMerKey(bankConfig.getIntrMerPravkeyPath());
		param.setUrl(aPayPabConfig.get("PAB_MERCHANT_SETTLED_URL"));
		param.setNotifyUrl(aPayPabConfig.get("PAB_MERCHANT_SETTLED_NOTIFYURL"));
		return param;
	}

	/**
	 * 
	 * 功能描述：校验请求非空参数
	 *
	 * @param request
	 * @throws GopayException
	 * 
	 * @author 宣广海
	 *
	 * @since 2018年1月4日
	 *
	 * @update:[变更日期YYYY-MM-DD][更改人姓名][变更描述]
	 */
	@SuppressWarnings("rawtypes")
	private void checkRequest(MerchantSettledRequest request) throws GopayException {
		if (StringUtils.isBlank(request.getChannelCode())) {
			logger.error("商户入驻添加商户获取银行渠道为空！");
			throw new GopayException(ProcCodeConstants.PROC_CODE_100E6090);
		}
	}

	/**
	 * 
	 * 功能描述：根据银行渠道判断业务处理bean
	 *
	 * @param inChann
	 * @return
	 * @throws GopayException
	 * 
	 * @author 宣广海
	 *
	 * @since 2018年1月4日
	 *
	 * @update:[变更日期YYYY-MM-DD][更改人姓名][变更描述]
	 */
	private String getBeanName(String inChann) throws GopayException {
		String beanName = null;
		if (BisBankInterfaceChannel._25.value.equals(inChann)) {
			beanName = "PAB-MERSETTLED";
		}
		if (StringUtils.isBlank(beanName)) {
			throw new GopayException(ProcCodeConstants.PROC_CODE_100E7022);
		}
		return beanName;
	}

}
